﻿#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QPushButton>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget),id1(0),id2(0)
{
    ui->setupUi(this);
    //启动定时器
    id1=startTimer(1000);//单位是毫秒startTimer(1000);//单位是毫秒
    id2=startTimer(2000);

    //定时器的类
    QTimer *time=new QTimer(this);
    //
    connect(ui->pushButton,&QPushButton::click,[=](){
        time->stop();
    });

    time->start(500);
    connect(time,&QTimer::timeout,[=](){
        static int num=1;
        ui->label_3->setText(QString::number(num++));
    });


}

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *ev){
    if(ev->timerId()==1){
        static int num=1;
        ui->label->setText(QString::number(num++));
    }

    else{
        static int num2=1;
        ui->label_2->setText(QString::number(num2++));
    }
}
